<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
$employee_query = mysql_query("select IDEmployee, FullName, State, EmployeeCode, CMND, BankName, BankAccount,DATE_FORMAT(Birthday,'%Y-%m-%d') as Birthday, Sex,DATE_FORMAT(StartDate,'%Y-%m-%d') as StartDate, Email, Mobile, Phone, Address, 
	IDDepartment , IDRole , Position , Accountant , CurrentJob , Description , EndDate,Type_employee,Positionsit,GraduateDegree
  from employee where IDEmployee = ".$id." limit 1");
if (mysql_num_rows($employee_query)>0) {
	$employeeinfo = mysql_fetch_array($employee_query);
	$temp_start = explode(" ", $employeeinfo[StartDate]);
	$temp_start = strtotime($temp_start[0]);
	$temp_end = explode(" ", $employeeinfo[EndDate]);
	$temp_end = strtotime($temp_end[0]); 
	if($temp_end==""){
		$temp_end=strtotime("now");
	}
	if($employeeinfo[EndDate]=="0000-00-00 00:00:00"){
		$temp_end=strtotime("now");
	}
	if($employeeinfo[CurrentJob]==""){
		$repon = " ";
	}else
		$repon = $employeeinfo[CurrentJob];
}else{
	header('../../login.php');
}
?>

<link  href="admin/css/jsDatePick_ltr.min.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
	new JsDatePick({
		useMode:2,
		target:"birthday",

		dateFormat:"%Y-%m-%d"
	});
	new JsDatePick({
		useMode:2,
		target:"startwork",

		dateFormat:"%Y-%m-%d"
	});
};


function checkRetypePassword(){
	var pass = $('input#newpassword').val();
	var retypepass = $('input#retypepassword').val();
	if (pass == retypepass) {
		$('label#error_retype').hide();
	}else{
		$('label#error_retype').show();
	}
}

function checkSubmitPassword(){
	var pass = $('input#newpassword').val();
	var retypepass = $('input#retypepassword').val();
	if (pass == retypepass) {
		$('label#error_retype').hide();
		if(pass==""){
			$('input#newpassword').focus();
			return false;
		}else if (retypepass == ""){
			$('input#retypepassword').focus();
			return false;
		}
		return true;
	}else{
		$('label#error_retype').show();
		$('input#retypepassword').focus();
		return false;
	}
}

</script>

<?php 

$sqldeparment = mysql_query("SELECT dl.IDDepartment,dl.DepartmentName FROM department_lang dl WHERE dl.LangID='".$_SESSION['lang']."' ORDER BY dl.IDDepartment;");

$sqlrole = mysql_query("SELECT IDRole,Description from roles ");

$sqlsex = mysql_query("select ac_sex.SexID,ac_sex_lang.SexName  from ac_sex , ac_sex_lang	where ac_sex.SexID=ac_sex_lang.SexID 
			            				and ac_sex_lang.LangID='".$_SESSION['lang']."'");

$sqltypeemp = mysql_query("select tyemp.IDTypeEmpl,typlang.TypeEmplName from type_employee tyemp,type_employee_lang typlang
					where tyemp.IDTypeEmpl = typlang.IDTypeEmpl and typlang.IDLang='".$_SESSION['lang']."'");
?>
<div id="contains" style="background-color: #edf4f7;">

	<div class="title"></div>
	<div class="body">
	<form action="admin/employeemanagement/process-edit-account-working.php" id="formregister" method="post">
		<div id="storeForm" style="margin-left: 5px;">
			<span id="head"><?=$l_update?></span>
			<div id="content">
			<span
					style="padding: 3px 3px 0px 3px; color: #508E21;"> <?=$l_personaldetail?>
				</span>
				<input type="hidden" name="idemployee" value="<?=$employeeinfo[IDEmployee]?>"/>
				<table style="border-top: 1px dotted silver">
					<tr>
						<td width="15%" class="tdFirst"><?=$l_fullname?> :</td>
						<td width="35%"><input id="fulln" name="fulln" type="text"
							value="<?=$employeeinfo[FullName]?>" maxlength="100" style="width: 100%;"
							class="textfiledCompany" autocomplete="off"/>
						</td>
						<td width="15%" class="tdFirst"><?=$l_state?> :</td>
						<td width="35%">
						<select name="state" id="state"  size="1"
							style="width: 100%;height: 26px;">
							<option value="1" id="1" <?if($employeeinfo[State]=='1'){?> selected="selected"<?php }?>><?=$l_working ?></option>
							<option value="0" id="0" <?if($employeeinfo[State]=='0'){?> selected="selected"<?php }?>><?=$l_left ?></option>
						</select>
						</td>
					</tr>
					
					<tr>
						<td width="150px" class="tdFirst"><?=$l_employeecode?> :</td>
						<td width="35%"><input id="employeeCode" name="employeeCode"
							type="text" value="<?=$employeeinfo[EmployeeCode]?>" maxlength="20" style="width: 100%;"
							class="textfiledCompany" /></td>
						<td width="150px" class="tdFirst"><?=$l_cmnd?> :</td>
						<td width="35%"><input id="identity" name="identity" type="text"
							value="<?=$employeeinfo[CMND]?>" maxlength="50" style="width: 100%;"
							class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_bankname?> :</td>
						<td width="35%"><input id="bankName" name="bankName" type="text"
							value="<?=$employeeinfo[BankName]?>" maxlength="50" style="width: 100%;"
							class="textfiledCompany" /></td>
						<td width="15%" class="tdFirst"><?=$l_bankaccount ?> :</td>
						<td width="35%"><input id="bankAccount" name="bankAccount"
							type="text" value="<?=$employeeinfo[BankAccount]?>" maxlength="50" style="width: 100%;"
							class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="150px" class="tdFirst"><?=$l_birthday?> :</td>
						<td width="35%"><span style="z-index: 1;"><span style="white-space: nowrap;">
							<input id="birthday" name="birthday" value="<?=$employeeinfo[Birthday]?>"
								type="text" value="" maxlength="50" style="width: 100%;"
								class="textfiledCompany" /></span> </span></td>
						<td width="15%" class="tdFirst"><?=$l_sex?> :</td>
						<td width="35%"><select id="sex" name="sex" size="1"
							style="width: 100%;height: 26px;">
							<?php while ($row = mysql_fetch_array($sqlsex)){?>
								<option value="<?=$row[SexID]?>" <?if($row[SexID] == $employeeinfo[Sex]){?> selected="selected"<?php }?>><?php echo $row[SexName];?></option>
								<?php }?>
						</select></td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_startwork?> :</td>
						<td width="35%"><span style="z-index: 1;"><span style="white-space: nowrap;">
							 <input id="startwork" name="startwork"
								type="text" value="<?=$employeeinfo[StartDate]?>" maxlength="50" style="width: 100%;"
								class="textfiledCompany" /> </span> </span></td>

						<td width="15%" class="tdFirst"><?=$l_email?> :</td>
						<td width="35%"><input id="mail" value="<?=$employeeinfo[Email]?>" name="mail" type="text"
							maxlength="200" style="width: 100%;" class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_mobile?> :</td>
						<td width="35%"><input id="mobile" name="mobile" type="text"
							maxlength="30" value="<?=$employeeinfo[Mobile]?>" style="width: 100%;" class="textfiledCompany" />
						</td>
						<td width="15%" class="tdFirst"><?=$l_phone?> :</td>
						<td width="35%"><input id="phone" name="phone" type="text"
							maxlength="20" value="<?=$employeeinfo[Phone]?>" style="width: 100%;" class="textfiledCompany" /></td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_address?> :</td>
						<td width="35%"><textarea id="address" name="address" style="width: 100%;min-height: 43px;" class="textareaEmp"><?=$employeeinfo[Address]?></textarea>
						</td>
						
						<td width="15%" class="tdFirst"><?=$l_type_employee?> :</td>
						<td width="35%">
							<select id="typeemployee" name="typeemployee" size="1"
								style="width: 100%;height: 26px;">
								<?php while ($rowtype = mysql_fetch_array($sqltypeemp)){
									if($_SESSION['db']=='elitech'){
										if($rowtype[IDTypeEmpl]!=0 && $rowtype[IDTypeEmpl]!=3 ){
										?>
										<option value="<?=$rowtype[IDTypeEmpl]?>" 
											<?php if ($rowtype[IDTypeEmpl] == $employeeinfo[Type_employee]){?> selected="selected" <?php }?>>
											<?php echo $rowtype[TypeEmplName];?></option>
										<?php }
									}else {
										if($rowtype[IDTypeEmpl]!=3 ){
											?>
											<option value="<?=$rowtype[IDTypeEmpl]?>" 
												<?php if ($rowtype[IDTypeEmpl] == $employeeinfo[Type_employee]){?> selected="selected" <?php }?>>
												<?php echo $rowtype[TypeEmplName];?></option>
											<?php }
										}
									}?>
							</select>
						</td>
						
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_sitting_position?> :</td>
						<td width="35%"><input type="text" id="positionsit" name="positionsit" value="<?=$employeeinfo['Positionsit']?>" style="width: 100%;" class="textfiledCompany"> 
						</td>
						<td width="15%" class="tdFirst"><?=$l_graduatedegree?> :</td>
						<td width="35%"><input id="graduatedegree" name="graduatedegree" type="text" style="width: 100%;" class="textfiledCompany"  value="<?=$employeeinfo['GraduateDegree']?>"/>
							
						</td>
						
					</tr>
				</table>
				<span
					style="border-bottom: 1px dotted silver; display: block; padding: 3px 3px 0px 3px; color: #508E21;">
					<?=$l_positioninfo?> </span>
				
				<table >
					<tr>
						<td width="150px" class="tdFirst"><?=$l_department?> :</td>
						<td width="35%"><select id="department" name="department" size="1"
							style="width: 100%;height: 22px;">
							<?php while($row=mysql_fetch_array($sqldeparment)){?>
								<option value="<?=$row[IDDepartment]?>" <?if($row[IDDepartment] == $employeeinfo[IDDepartment]){?> selected="selected"<?php }?> ><?php echo $row['DepartmentName']?></option>
								<?php }?>
						</select></td>
						<td width="150px" class="tdFirst"><?=$l_accessright?> :</td>
						<td width="35%"><select id="roleaccess" name="roleaccess" size="1"
							style="width: 100%;height: 26px;">
							<?php while ($rowrole = mysql_fetch_array($sqlrole)){?>
								<option value="<?=$rowrole[IDRole]?>" <?if($rowrole[IDRole] == $employeeinfo[IDRole]){?> selected="selected"<?php }?>><?php echo $rowrole[Description];?></option>
								<?php }?>
						</select></td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_position?> :</td>
						<td width="35%"><input id="position" name="position" type="text"
							maxlength="200" value="<?=$employeeinfo[Position]?>" style="width: 100%;" class="textfiledCompany" />
						</td>
						<td class="tdFirst" width="15%"><?=$l_accountant?> :</td>
						<td width="35%"><table style="width: 100px">
								<tr>
									<td><input id="accountant" type="radio" name="accountant" value="1" <?if($employeeinfo[Accountant]==1){?> checked="checked"<?php }?>/><label>
											<?=$l_yes?></label></td>
									<td><input id="accountant" type="radio" name="accountant" <?if($employeeinfo[Accountant]==0){?> checked="checked"<?php }?>
										value="0" /><label> <?=$l_No?></label></td>
								</tr>
							</table></td>
					</tr>
					<tr>
						<td valign="top" width="15%" class="tdFirst"><?=$l_responsibilities?> :</td>
						<td colspan="5"><input name="currentJob"  id="currentJob"
 							type="text"  maxlength="100" style="width: 515px" value="<?=$repon?>"
							class="textfiledCompany" autocomplete="off"/></td>
					</tr>
					<tr>
						<td valign="top" width="15%" class="tdFirst"><?=$l_description?> :</td>
						<td colspan="3"><textarea id="description" name="description"
								class="textareaEmp" ><?=$employeeinfo[Description]?></textarea></td>
					</tr>
				</table>
				<span
					style="border-top: 1px dotted silver; display: block; height: 2px;"></span>
				<table style="width:100%; margin-top: 9px;border: none !important">
					<tr style="border: none !important">
						<td style="border: none !important; color: #508E21"> <?=$l_totaldays?>: <?=(floor($temp_end / (60 * 60 * 24)) - floor($temp_start / (60 * 60 * 24)))?> <?=$l_days?> 
						</td>
						<td align="right" style="border: none !important"> <input id="update" name="update" type="submit" value="<?=$l_update?>" 
							class="buttonNormal" /> 
						</td>
					</tr>
					
				</table>
			</div>
		</div>
		</form>
		<form action="admin/employeemanagement/process-edit-account-working.php" id="formregister" method="post" onsubmit="return checkSubmitPassword();" >
		<div id="storeForm" style="margin-left: 5px;">  
			<span id="head"><?=$l_changepassword?></span>
			<div id="content">
			<input type="hidden" name="idemployee" value="<?=$employeeinfo[IDEmployee]?>"/>
				<table>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_newpassword?> :</td>
						<td width="79%"><input id="newpassword" name="newpassword" type="password"
							value="" maxlength="100" style="width: 100%;" autocomplete="off"
							class="textfiledCompany" />
						</td>
						<td width="5%"></td>
						
					</tr>
					
					<tr>
						<td  class="tdFirst"><?=$l_retypepassword?> :</td>
						<td ><input id="retypepassword" name="retypepassword" type="password"
							value="" maxlength="100" style="width: 100%;" autocomplete="off"
							class="textfiledCompany" onchange="checkRetypePassword()" /> 
						</td>
						<td  align="center"><label id="error_retype" style="color : red; display:none"> X </label></td>
					</tr>
					
				</table>
				<span
					style="border-top: 1px dotted silver; display: block; height: 2px;"></span>
				<div style="text-align: right; margin-top: 10px">
					<input id="updatePass" name="updatePass" type="submit" value="<?=$l_update?>" 
						class="buttonNormal" />
				</div>
			</div>
		</div>
</form>
	</div>
</div>
